﻿<controlsMetro:MetroWindow x:Class="EasyToolkit.Excel.UI.SortAndFilter.SortAndFilerWindow"
                           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                           xmlns:sys="clr-namespace:System;assembly=mscorlib"
                           xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                           xmlns:controlsMetro="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                           xmlns:easyToolkitAssembly="clr-namespace:EasyToolkit.UI;assembly=EasyToolkit"
                           xmlns:local="clr-namespace:EasyToolkit.Excel.UI.SortAndFilter"
                           xmlns:localConverters="clr-namespace:EasyToolkit.Excel.UI.SortAndFilter.Converters"
                           
                           ShowTitleBar="True"
                           WindowStartupLocation="CenterOwner"
                           GlowBrush="{DynamicResource AccentColorBrush}"
                           Title="Sort And Filer" Height="550" Width="800"
>
    <Window.Resources>
        <ResourceDictionary>
            <BooleanToVisibilityConverter x:Key="BoolToVis" />
            <sys:Double x:Key="ToggleSize">25</sys:Double>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/EasyToolkit;component/UI/Resources/Icons.xaml" />
                <ResourceDictionary Source="pack://application:,,,/EasyToolkit;component/UI/Resources/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Teal.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Grid Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="115"/>
        </Grid.ColumnDefinitions>

        <Grid >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="5"/>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <GroupBox Grid.Column="0" Header="Property List" Margin="5">
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" BorderThickness="0">
                    <ItemsControl ItemsSource="{Binding Path=TemplateViewModels}" HorizontalContentAlignment="Stretch">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Expander IsExpanded="True" Margin="0,2,0,0">
                                    <Expander.Header>
                                        <Grid ToolTip="{Binding Description}">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition SharedSizeGroup="TempName" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Grid.Column="0" Text="{Binding Name}" Foreground="White"/>
                                            <TextBlock Grid.Column="1" Text="{Binding Label}" Foreground="White"/>
                                        </Grid>
                                    </Expander.Header>
                                    <Expander.Content>
                                        <ListBox ItemsSource="{Binding Path=BindingDefinitions}" SelectedItem="{Binding SelectedBindingDefinition, Mode=TwoWay}" VerticalContentAlignment="Center" HorizontalContentAlignment="Stretch" ItemContainerStyle="{StaticResource ListBoxItemNoVisibleSelection}">
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <Border BorderThickness="{Binding IsSortOrFilterSelected, Converter={localConverters:SelectionConverter}}" BorderBrush="Red" Margin="0,1,0,1" Padding="{Binding IsSortOrFilterSelected, Converter={localConverters:SelectionMarginConverter}}">
                                                        <Grid>
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="auto" />
                                                                <ColumnDefinition Width="auto" />
                                                                <ColumnDefinition />
                                                            </Grid.ColumnDefinitions>
                                                            <StackPanel Grid.Column="0" Orientation="Horizontal" >
                                                                <ToggleButton IsChecked="{Binding IsSortAscending}" Width="{StaticResource ToggleSize}" Height="{StaticResource ToggleSize}" ToolTip="Sort Ascending" Margin="0,0,2,0">
                                                                    <Path Stretch="Fill" DataContext="{StaticResource icon_Sort}" Data="{Binding Path=Data}" Fill="{DynamicResource HighlightBrush}" />
                                                                </ToggleButton>
                                                                <ToggleButton IsChecked="{Binding IsSortDescending}" Width="{StaticResource ToggleSize}" Height="{StaticResource ToggleSize}" ToolTip="Sort Descending">
                                                                    <Path Stretch="Fill" DataContext="{StaticResource icon_SortDescending}" Data="{Binding Path=Data}" Fill="{DynamicResource HighlightBrush}" />
                                                                </ToggleButton>
                                                                <Separator Style="{StaticResource VerticalSeparator}" Background="{DynamicResource AccentColorBrush}"/>
                                                            </StackPanel>
                                                            <StackPanel Grid.Column="1" Orientation="Horizontal">
                                                                <ToggleButton IsChecked="{Binding IsFilterOnValues}" Width="{StaticResource ToggleSize}" Height="{StaticResource ToggleSize}" ToolTip="Filter on values" Margin="0,0,2,0">
                                                                    <Path Stretch="Fill" DataContext="{StaticResource icon_FilterValuesSelect}" Data="{Binding Path=Data}" Fill="{DynamicResource HighlightBrush}" />
                                                                </ToggleButton>
                                                                <ToggleButton IsChecked="{Binding IsFilterWithConditions}" Width="{StaticResource ToggleSize}" Height="{StaticResource ToggleSize}" ToolTip="Filter with conditions">
                                                                    <Path Stretch="Fill" DataContext="{StaticResource icon_FilterCondition}" Data="{Binding Path=Data}" Fill="{DynamicResource HighlightBrush}" />
                                                                </ToggleButton>
                                                            </StackPanel>
                                                            <TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Description}" Margin="5,0,5,0"/>
                                                        </Grid>
                                                    </Border>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ListBox>
                                    </Expander.Content>
                                </Expander>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </GroupBox>


            <GridSplitter Margin="0,5,0,5" Grid.Column="1" Background="{DynamicResource AccentColorBrush4}" HorizontalAlignment="Stretch"/>

            <Grid Grid.Column="2">
                <local:FilterOnValue Visibility="{Binding Path=SelectedDefinitionHasFilterOnValue, Converter={StaticResource BoolToVis}}" IsEnabled="{Binding Path=SelectedDefinitionFilterOnValueEnabled}"/>
                <local:FilterOnCondition Visibility="{Binding Path=SelectedDefinitionHasFilterOnCondition, Converter={StaticResource BoolToVis}}"/>
            </Grid>
        </Grid>

        <StackPanel Grid.Column="1" Margin="5,5,0,5" Background="WhiteSmoke" Orientation="Vertical">
            <TextBlock Margin="0,10,0,0" FontSize="18"  FontWeight="Light" Text="Actions" Foreground="{DynamicResource AccentColorBrush}" HorizontalAlignment="Center"/>
            <Separator Height="15" Background="{DynamicResource AccentColorBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Top"/>
            <Button FontSize="14" FontWeight="Medium" Margin="5,5,5,0" Content="Apply" Style="{DynamicResource AccentedSquareButtonStyle}" Foreground="White" Command="{Binding ApplySortAndFilterCommand}"/>
            <Button FontSize="14" FontWeight="Medium" Margin="5,5,5,0" Content="Cancel" Style="{DynamicResource AccentedSquareButtonStyle}" Command="{x:Static easyToolkitAssembly:MetroFormWpfContainer.CloseWindowCommandRouted}" Foreground="White"/>
            <Separator Height="15" Background="{DynamicResource AccentColorBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Top"/>
            <Button FontSize="14" Margin="5,5,5,0" Content="Reset All" Style="{DynamicResource AccentedSquareButtonStyle}" Foreground="White" Command="{Binding ResetAllCommand}"/>
            <Button FontSize="14" FontWeight="Medium" Margin="5,5,5,0" Content="Reset Filters" Style="{DynamicResource AccentedSquareButtonStyle}" Foreground="White" Command="{Binding ResetAllFiltersCommand}"/>
            <Button FontSize="14" FontWeight="Medium" Margin="5,5,5,0" Content="Reset Sorters" Style="{DynamicResource AccentedSquareButtonStyle}" Foreground="White" Command="{Binding ResetAllSortersCommand}"/>
        </StackPanel>
    </Grid>
</controlsMetro:MetroWindow>
